<%@ page language="java" contentType="text/html; charset=EUC-KR"
   import="java.io.*"%> 
<html>
<body>
<%
    request.setCharacterEncoding("utf-8");
	String filename = request.getParameter("file1");	
	String dir = application.getRealPath("/upload");
		
	File file = new File(dir+"/"+ filename);
	
	response.setContentType("application/x-msdownload");	
	//response.setHeader("Content-Disposition",  "attachment; filename=aa.txt;" 
   	
   	response.setHeader("Content-Disposition",  "attachment; filename=" 
   	         + new String(file.getName().getBytes("MS949"), "ISO-8859-1") + ";");
	response.setHeader("Content-Length", ""+file.length() );

	BufferedInputStream bin = null;
	BufferedOutputStream bos = null;
	
  try {
      bin = new BufferedInputStream( new FileInputStream(file) );
      bos = new BufferedOutputStream( response.getOutputStream() );
        	 
      byte[] buf = new byte[(int)file.length()]; //buffer size 2K.
      int read = 0;
      while ((read = bin.read(buf)) != -1) {
          bos.write(buf,0,read);
      }  
  } finally {
      bos.close();
      bin.close();
  } 
%>
</body>
</html>